package com.wl.willChat.base

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.wl.willChat.R

abstract class BaseActivity: AppCompatActivity() {
    private lateinit var binding:ViewDataBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding=DataBindingUtil.setContentView(this,getLayoutId())
        initViewModel()
        observe()
        init(savedInstanceState)
    }

    /**
     * 获取layout布局
     */
    abstract fun getLayoutId():Int

    open fun getViewDataBinding():ViewDataBinding{
        return binding
    }

    /**
     * 初始化viewModel
     * 之所以没有设计为抽象，是因为部分简单activity可能不需要viewModel
     * observe同理
     */
    open fun initViewModel() {
    }

    /**
     * 注册观察者
     */
    open fun observe() {

    }

    /**
     * activity入口
     */
    abstract fun init(savedInstanceState: Bundle?)

    private fun initData(){

    }

    private fun showLoadingDialog(){

    }

    fun log(str:String){
        Log.e("WILLCHAT===",str)
    }

    fun showToast(str: String){
        Toast.makeText(applicationContext,str,Toast.LENGTH_LONG).show()
    }
}